using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PACKETPARSERMAX20.CORE
{
	public class instance_template : MangosBase
	{
		public System.UInt16? map;
		public System.UInt16? parent;
		public System.Byte? levelmin;
		public System.Byte? levelmax;
		public System.String script;




		public override string GetInsertCommand()
		{
			return string.Format("INSERT IGNORE INTO `instance_template` (`map`, `parent`, `levelmin`, `levelmax`, `script`) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}');", map.GetValueOrDefault(), parent.GetValueOrDefault(), levelmin.GetValueOrDefault(), levelmax.GetValueOrDefault(), script.MySQLDBString());
		}


		public override string GetUpdateCommand()
		{
            StringBuilder sb = new StringBuilder();
						sb.Append("UPDATE `instance_template` SET ");
			if(parent != null)
			{
				sb.AppendLine("`parent`='" + parent.Value.ToString() + "'");
			}
			if(levelmin != null)
			{
				sb.AppendLine("`levelmin`='" + levelmin.Value.ToString() + "'");
			}
			if(levelmax != null)
			{
				sb.AppendLine("`levelmax`='" + levelmax.Value.ToString() + "'");
			}
			if(script != null)
			{
				sb.AppendLine("`script`='" + script.MySQLDBString() + "'");
			}
				sb = sb.Replace("\r\n", ", ");
				sb.Append(" WHERE `map`='" + map.Value.ToString() + "';");
				sb = sb.Replace(",  WHERE", " WHERE");

            return sb.ToString();
		}


	}
}
